class BuyersController < ApplicationController
  def index
    params[:key_word] = "%#{params[:key_words]}%"
    @buyers = Buyer.where('full_name like :key_word or mobile like :key_word or address like :key_word',params).order('created_at asc')
  end
  
  def new
    @buyer = Buyer.new
  end
  
  def create
    @buyer = Buyer.new(params[:buyer])
    if @buyer.save
      redirect_to :action => :index
    else
      render :new
    end
  end
  
  def edit
    @buyer = Buyer.find(params[:id])
  end
  
  def update
    @buyer = Buyer.find(params[:id])
    if @buyer.update_attributes(params[:buyer])
      redirect_to :action => :index
    else
      render :edit
    end
  end
  
#  def destroy
#    @buyer = Buyer.find(params[:id])
#    @buyer.destroy
#    redirect_to :action => :index
#  end
end

